package leetcode.题库.数组.普通数组;

import java.util.Arrays;

/**
 * description: 最大数
 *
 * @author 颜真明
 * @date 2024/3/8  13:10
 */
public class Solution179 {
    public static void main(String[] args) {
        int[] nums = new int[]{3,30,34,5,9};
        System.out.println(largestNumber(nums));
    }
    public static String largestNumber(int[] nums) {
        int i = 0;
        String[] arr = new String[nums.length];
        StringBuilder res = new StringBuilder();
        for (int num : nums) {
            arr[i++] = String.valueOf(num);
        }
        Arrays.sort(arr,(s1,s2)->(s2+s1).compareTo(s1+s2));
        for (String s : arr) {
            res.append(s);
        }
        return arr[0].equals("0") ? "0" :res.toString();
    }
}
